package com.renwei.yunlong.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

import com.renwei.yunlong.R;
import com.renwei.yunlong.bean.ProblemInquireBean;
import com.zyf.fwms.commonlibrary.utils.AutoUtils;

import java.util.List;

/**
 * 服务商 问题查询
 *
 * Created by Administrator on 2017/9/13.
 */

public class ServiceProblemInquireAdapter extends RecyclerView.Adapter<ServiceProblemInquireAdapter.ServiceProblemInquireViewHolder>{

    private Context context;
    private LayoutInflater inflater;
    List<ProblemInquireBean.Rows> mList;

    private OnItemClickListener mOnItemClickListener;

    public ServiceProblemInquireAdapter(Context context, List<ProblemInquireBean.Rows> mList){
        this.context = context;
        inflater = LayoutInflater.from(context);
        this.mList = mList;
    }

    @Override
    public ServiceProblemInquireViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = inflater.inflate(R.layout.item_problem_inquire,null);
        AutoUtils.auto(view);
        return new ServiceProblemInquireViewHolder(view);
    }

    @Override
    public void onBindViewHolder(final ServiceProblemInquireViewHolder holder, int position) {
        final ProblemInquireBean.Rows rows = mList.get(position);
        holder.tvTitleContent.setText(rows.getContent());
        holder.tvDepartment.setText(rows.getDepartmentName());
        holder.tvName.setText("/"+rows.getRequestUserName());
        String[] dateTime = rows.getQuestionDate().split("T");
        holder.tvDate.setText(dateTime[0]);
        holder.tvTime.setText(dateTime[1]);
        //-1待审核，1处理中，2已解决，3未解决，4审核通过待处理，-4审核不通过，5已入库，6审核通过(已解决)，-6审核未通过(已解决)
        if ("-1".equals(rows.getEventState())){
            holder.btnStatus.setBackgroundResource(R.drawable.shape_red_card);
        }else if ("1".equals(rows.getEventState())){
            holder.btnStatus.setBackgroundResource(R.drawable.shape_yellow_card);
        }else if ("2".equals(rows.getEventState())){
            holder.btnStatus.setBackgroundResource(R.drawable.shape_green_card);
        }else if ("3".equals(rows.getEventState())){
            holder.btnStatus.setBackgroundResource(R.drawable.shape_green_card);
        }else if ("4".equals(rows.getEventState())){
            holder.btnStatus.setBackgroundResource(R.drawable.shape_green_card);
        }else if ("-4".equals(rows.getEventState())){
            holder.btnStatus.setBackgroundResource(R.drawable.shape_green_card);
        }else if ("5".equals(rows.getEventState())){
            holder.btnStatus.setBackgroundResource(R.drawable.shape_green_card);
        }else if ("6".equals(rows.getEventState())){
            holder.btnStatus.setBackgroundResource(R.drawable.shape_green_card);
        }else if ("-6".equals(rows.getEventState())){
            holder.btnStatus.setBackgroundResource(R.drawable.shape_green_card);
        }
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int pos = holder.getLayoutPosition();
                mOnItemClickListener.onItemClick(holder.itemView,pos,rows.getRequestUserName());
            }
        });
    }

    @Override
    public int getItemCount() {
        return mList == null?0:mList.size();
    }

    public void setOnItemClickListener(OnItemClickListener onItemClickListener){
        this.mOnItemClickListener = onItemClickListener;
    }
    public interface OnItemClickListener{
        void onItemClick(View view, int position, String name);
    }


    static class ServiceProblemInquireViewHolder extends RecyclerView.ViewHolder{

        private View itemView;
        private TextView tvTitleContent;//问题描述
        private TextView tvDepartment;//部门
        private TextView tvName;//相应人员
        private TextView tvTime;//创建时间
        private TextView tvDate;//日期
        private Button btnStatus;//状态

        public ServiceProblemInquireViewHolder(View view) {
            super(view);
            itemView = view;
            tvName = (TextView) itemView.findViewById(R.id.tv_name);
            tvTitleContent = (TextView) itemView.findViewById(R.id.tv_title_content);
            tvDepartment = (TextView) itemView.findViewById(R.id.tv_department);
            tvTime = (TextView) itemView.findViewById(R.id.tv_time);
            btnStatus = (Button) itemView.findViewById(R.id.button);
            tvDate = (TextView) itemView.findViewById(R.id.tv_date);
        }
    }
}
